<?php
require_once('dataSource.php');
require_once('ingredientDao.php');
require_once('labelDao.php');
require_once('recipeDao.php');

function obtainCategories() {
	
	return findLabels();


}// end obtainCategories

function obtainRecipesByLabel($labelId) {

	$recipes = findRecipesByLabelId($labelId);

	if ($recipes) {
		$i = 0;
		foreach($recipes as $recipe) {
	
			$recipesMini[$i]["recipeId"] = $recipe["recipeId"];
			$recipesMini[$i]["title"] = $recipe["title"];
			$i = $i + 1;
		}
	
		return $recipesMini;
	}

}// end obtainRecipesByLabel

function obtainLabelById($labelId) {

	$label = findLabelByLabelId($labelId);

	return $label;

}// end obtainRecipeById


function obtainRecipeById($recipeId) {

	$result["recipe"] = findRecipeByRecipeId($recipeId);
	$result["ingredients"] = findByRecipe($recipeId);

	return $result;

}// end obtainRecipeById


function obtainRecipes() {

	$recipes = findRecipes();
	
	if ($recipes) {
		$i = 0;
		foreach($recipes as $recipe) {

			$recipesMini[$i]["recipeId"] = $recipe["recipeId"];
			$recipesMini[$i]["title"] = $recipe["title"];
			$i = $i + 1;
		}
		return $recipesMini;
	}

}// end obtainRecipes


function obtainLastRecipes($numberRecipes) {

	$recipes = findLastRecipes();
	if ($recipes) {
		$i = 0;
		foreach($recipes as $recipe) {
			$recipesMini[$i]["recipeId"] = $recipe["recipeId"];
			$recipesMini[$i]["title"] = $recipe["title"];
			$recipesMini[$i]["preparation"] = substr($recipe["preparation"],0,800) . "...";
			$recipesMini[$i]["date"] = $recipe["date"];
			$i = $i + 1;
		}
		return $recipesMini;
	}

}// end obtainLastRecipes



?>